import sys
sys.path.append("../")
from frameworks.cores.LoadClass import *
from RedisUtil import *
import json
import time

class ApiController:
    def __init__(self):
        self.load = LoadClass()
        self.redis = RedisUtil()

    def getHostListData(self,args):
        serversObj = self.redis.getAllList("servers")
        serversList = []
        for key in serversObj.keys():
            option = {}
            option["ip"] = key
            option["lasttime"] = serversObj[key]
            if int(time.time()) - int(serversObj[key]) < 60:
                option["status"] = "在线"
            else:
                option["status"] = "掉线"
            serversList.append(option)
        return serversList
